package theFirstWay;

public class ThreadPop implements Runnable{
    public int flag = 0;
    public int i=0;

    @Override
    public void run() {
            do {
                    System.out.println(i+"ThreadPop Start:");
                    while (flag != MainClass.sysFlag) {
//                        busy waiting;
                    }
//        critical section start
//        打印栈顶元素
                    if (!MainClass.stack.empty()) {
                        System.out.println(i+"栈顶元素:" + MainClass.stack.peek()+"开始执行pop操作");
                        MainClass.stack.pop();
                    } else {
                        System.out.println("空栈无法执行pop操作");
                    }
//        critical section end,让出临界区
                    MainClass.sysFlag = 1;
                    i++;
            } while (i < 1000);

        }

}
